<template>
  <view class="past-issues">
    <view class="title-container">
      <uni-icons 
        type="left" 
        size="22" 
        color="#333" 
        class="back-icon"
        @click="handleBack"
      />
      <view class="title-content">往期列表</view>
    </view>
    
    <!-- 月份列表 -->
    <view 
      class="month-item" 
      v-for="(item, index) in monthList" 
      :key="index"
      @click="goToImageList(item)"
    >
      <text class="month-text">{{ item.month }}.{{ item.year }}</text>
      <uni-icons type="right" size="18" color="#999" />
    </view>
  </view>
</template>

<script setup>
import { ref, onMounted } from 'vue'

const monthList = ref([])

const generateMonthList = () => {
  const startYear = 2012
  const startMonth = 10
  const now = new Date()
  const currentYear = now.getFullYear()
  const currentMonth = now.getMonth() + 1

  const monthNames = [
    "一月", "二月", "三月", "四月", "五月", "六月",
    "七月", "八月", "九月", "十月", "十一月", "十二月"
  ]
  const monthListTemp = []

  for (let year = currentYear; year >= startYear; year--) {
    const yearStart = (year === startYear) ? startMonth : 1
    const yearEnd = (year === currentYear) ? currentMonth : 12

    for (let month = yearEnd; month >= yearStart; month--) {
      monthListTemp.push({
        year: year.toString(),
        month: monthNames[month - 1],
        monthNum: month.toString().padStart(2, '0')
      })
    }
  }

  monthList.value = monthListTemp
}

const goToImageList = (item) => {
  uni.navigateTo({
    url: `/pages/image-text/imageList?year=${item.year}&month=${item.monthNum}`
  })
}

const handleBack = () => {
  uni.navigateBack({
    delta: 1
  })
}

onMounted(() => {
  generateMonthList()
})
</script>

<style scoped>
.past-issues {
  background-color: #fff;
  min-height: 100vh;
}

.title-container {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 15px 10px;
  border-bottom: 1px solid #eee;
  position: relative;
}

.back-icon {
  position: absolute;
  left: 10px;
  cursor: pointer;
}

.title-content {
  font-size: 18px;
  font-weight: bold;
  color: #333;
}

.month-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 50px;
  border-bottom: 1px solid #eee;
  padding: 0 10px;
  cursor: pointer;
}

.month-item:active {
  background-color: #f5f5f5;
}

.month-text {
  font-size: 16px;
  color: #999; 
}
</style>
    